package com.gxuwz.mapper;

import com.gxuwz.model.entity.Student;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface StudentMapper {

    // 根据stuID查询学生信息
    @Select("select * from sys_student where stuID = #{stuId}")
    Student selectStudentByStuId(String stuId);

    // 插入学生信息
    @Insert("INSERT INTO sys_student (stuID, classID, stuName, sex, address, stuTel, contact, contactTel, password)\n" +
            "VALUES (#{stuID}, #{classID}, #{stuName}, #{sex}, #{address}, #{stuTel}, #{contact}, #{contactTel}, #{password})")
    int register(Student student);

    // 根据stuID查询学生信息（与selectStudentByStuId功能相同）
    @Select("select * from sys_student where stuID = #{stuId}")
    Student selectUserByStuID(String stuId);

    // 更新学生信息
    @Update("UPDATE sys_student SET classID = #{classID}, stuName = #{stuName}, sex = #{sex}, address = #{address}" +
            "stuTel = #{stuTel}, contact = #{contact}, contactTel = #{contactTel}, password = #{password} " +
            "WHERE stuID = #{stuID}")
    int updateStudent(Student student);

    // 根据stuID删除学生信息
    @Delete("DELETE FROM sys_student WHERE stuID = #{stuId}")
    int deleteStudentByStuId(String stuId);

    // 查询所有学生信息
    @Select("select * from sys_student")
    List<Student> selectAllStudents();
}
